package br.com.jbssistemas.loterica.managedbeans;

import br.com.jbssistemas.loterica.enums.Relatorio;
import br.com.jbssistemas.loterica.sevice.RelatorioService;
import br.com.jbssistemas.loterica.util.DateUtil;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.faces.view.ViewScoped;

/**
 *
 * @author daniel
 */
@Named(value = "relatorioBean")
@ViewScoped
public class RelatorioBean {
    
    private Date dataInicial;
    private Date dataFinal;
    
    private final RelatorioService relatorioService;
    
    private Relatorio relatorio;
    
    public RelatorioBean() {
        
        relatorioService = new RelatorioService();
        
        dataInicial = DateUtil.getDataInicialMesCorrente();
        
        dataFinal = DateUtil.getDataFinalMesCorrente();
        
    }

    public Date getDataInicial() {
        return dataInicial;
    }

    public void setDataInicial(Date dataInicial) {
        this.dataInicial = dataInicial;
    }

    public Date getDataFinal() {
        return dataFinal;
    }

    public void setDataFinal(Date dataFinal) {
        this.dataFinal = dataFinal;
    }

    public Relatorio getRelatorio() {
        return relatorio;
    }

    public void setRelatorio(Relatorio relatorio) {
        this.relatorio = relatorio;
    }

    public Relatorio[] getRelatorios(){
    
        return Relatorio.values();
        
    }
    
    public void imprimirRelatorio(){
    
        try {
            
            relatorioService.imprimirRelatorio(relatorio.getDiretorio(), relatorio.getNome(), dataInicial, dataFinal);
            
        } catch (Exception e) {
            
            Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, e);
            
        }
        
    }
    
}
